package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.feign.OrderFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author: cheng song
 * @Description:
 * @Date: Created in 17:04 2021/9/5
 * @ModifiedBy:
 */
@RestController
//@DefaultProperties(defaultFallback = "globalFallbackMethod")
public class OrderHystrixController {
    @Resource
    private OrderFeignService orderFeignService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id) {
//        int i = 10 / 0;
        return orderFeignService.paymentInfo_OK(id);
    }


    /**
     * 超时访问
     *
     * @param id
     * @return
      */
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    //@HystrixCommand(fallbackMethod = "paymentTimeOutFallbackMethod", commandProperties = {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")})
//    @HystrixCommand
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id) {
//        int i = 10 / 0;
        return orderFeignService.paymentInfo_TimeOut(id);
    }

    public String paymentTimeOutFallbackMethod(@PathVariable("id") Integer id) {
        return "我是消费者80,对方支付系统繁忙请10秒种后再试或者自己运行出错请检查自己,o(╥﹏╥)o";
    }

    public String globalFallbackMethod() {
        return "全局兜底方法";
    }
}
